#include<iostream> 
using namespace std;
const int N = 2e5 + 10;
long long f[N];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		long long x; cin >> x;
		f[i] = f[i - 1] + x;
	}
	long long ret = -1e20;
	long long minvalue = 0;
	for(int i = 1; i <= n; i++)
	{
		ret = max(ret,f[i] - minvalue);
		minvalue = min(minvalue,f[i]);
	}
	cout << ret << endl;
	return 0;
} 
